<template>
	<view class="train-detail-page">
		<view style="width: 100%;height: 185px;"><img style="width: 100%;height: 185px;" :src="img" alt=""></view>
		<view style="padding: 32rpx;">
			<view style="font-size: 30rpx;font-weight: 600;margin: 20rpx 0;">{{formData.title}}</view>
			<view style="font-size: 28rpx;margin: 20rpx 0;color:#aaa;position: relative;">
				已报名人数：{{formData.entryNum ? formData.entryNum:0}} 
				<view class="state-sty" style="color: #ffa52d;font-size: 36rpx;">￥{{formData.tuition}}</view>
			</view>
			<view class="info-sty">
				<view>报名时间: <text>{{formData.atB}}至{{formData.atA}}</text></view>
				<view>开课时间: <uni-dateformat format="yyyy-MM-dd" :threshold="[0, 0]" :date="formData.attendClass"></uni-dateformat></view>
				<view>总课时： <text>{{formData.classTime}}</text></view>
				<view>培训地点：<text>{{formData.classAddress}}</text></view>
			</view>
			<view class="lv-area-sty">
				<view>级别</view>
				<view class="lv-fla-sty">{{formData.classLevel == 0 ? '初级': formData.classLevel == 1?'中级':'高级'}}</view>
			</view>
			<view class="info-area-sty">
				<view style="padding: 5px 0;font-size: 36rpx;">课程介绍：</view>
				<view v-html="formData.introduce"></view>
			</view>
		</view>
		<view class="bottom-area-sty" v-if="formData.state == 0">
			<view></view>
			<view class="bm-btn-sty" @click="entryBtn">立即报名</view>
		</view>
	</view>
</template>

<script>
	const db = uniCloud.database();
	const dbCmd = db.command;
	import {
		filterArticles
	} from '@/utils/baseFn.js';
	export default {
		data() {
			return {
				formData: {},
				img: '',
				userInfo: {},
				glabalData: {
					screenWidth: 0,
					screenHeight: 0
				}
			}
		},
		onLoad(op) {
			const _this = this
			this.getDetail(op.id)
			uni.getStorage({
				key: 'userInfo',
				success: function(res) {
					console.log(res.data)
					if (res.data) {
						_this.userInfo = res.data
					}
				}
			})
		},
		onShow () {
			const info = wx.getSystemInfoSync()
			this.glabalData = {
			    screenWidth: info.screenWidth,
			    screenHeight: info.screenHeight
			}
		},
		created (op) {},
		mounted (op) {},
		methods: {
			getDetail(id) {
				uni.showLoading({
					mask: true
				})
				db.collection('course-MGMT').doc(id).field(
					"title,classLevel,applicationTime,attendClass,classTime,tuition,introduce,classAddress,state,annexId,deleted_at").get().then((res) => {
					const data = res.result.data[0]
					if (data) {
						const file = data.annexId.split(',')
						data.introduce = filterArticles(data.introduce, this.glabalData)
						this.img = `${this.$baseImgUrl}${file[0]}`
						data.applicationTime = JSON.parse(data.applicationTime)
						data.atB = data.applicationTime[0].substring(0,10)
						data.atA = data.applicationTime[1].substring(0,10)
						data.stateNm = data.state == 0 ? '报名中' : data.state == 1 ? '报名结束' : '已开课'
						this.formData = data
					}
				}).catch((err) => {
					uni.showModal({
						content: err.message || '请求服务失败',
						showCancel: false
					})
				}).finally(() => {
					uni.hideLoading()
				})
			},
			previewImage (row) {
				var current = row.url
				const arr = []
				this.imgList.map(img => {
					arr.push(img.url)
				})
				uni.previewImage({
					current: current,
					urls: arr,
					success: (e) => {
						console.log(e, 'success--previewImagepreviewImage')
					},
					fail: (e) => {
						console.log(e, 'fail--previewImagepreviewImage')
					}
				})
			},
			entryBtn () {
				const parm = {
					id: this.formData._id,
					classLevel: this.formData.classLevel,
					state: this.formData.state,
					title: this.formData.title,
					tuition: this.formData.tuition,
					allClassTime: this.formData.classTime
				}
				uni.navigateTo({
					url: `../register/studentRegister?parm=${JSON.stringify(parm)}`
				});
			}
		}
	}
</script>

<style>
	.train-detail-page {
		background-color: #f7f8fc;
		height: 100vh;
	}
	.state-sty {
		width: 75px;
		height: 30px;
		line-height: 30px;
		color: #fff;
		border-radius: 2px;
		text-align: center;
		position: absolute;
		top: 0;
		right: 0;
	}
	.lv-fla-sty {
		width: 75px;
		height: 30px;
		line-height: 30px;
		color: #fff;
		border-radius: 2px;
		text-align: center;
		background-color: #ffa52d;
		margin-top: 12px;
	}
	.info-sty {
		font-size: 24rpx;
		color: #aaa;
		margin-top: 20rpx;
	}
	.info-sty view {
		margin: 10rpx 0;
	}
	.info-sty text {
		color: #333;
		display: inline-block;
		margin-left: 10rpx;
	}
	.lv-area-sty {
		margin-top: 20px;
		padding: 30rpx;
		background-color: #fff;
		border-radius: 10px;
		height: 88px;
	}
	.info-area-sty {
		margin: 20px 0;
		padding: 30rpx;
		background-color: #fff;
		border-radius: 10px;
		padding-bottom: 50px;
	}
	.bottom-area-sty {
		width: 100%;
		height: 45px;
		background-color: #fff;
		position: fixed;
		bottom: 0;
	}
	.bm-btn-sty {
		width: 30%;
		height: 45px;
		text-align: center;
		background-color: #ffa52d;
		color: #fff;
		line-height: 45px;
		font-size: 32rpx;
		float: right;
	}
	.fwb-img {
	  max-width: 100%;
	  margin: 10px 0;
	}
</style>
<style lang="scss">
</style>